package com.mapper.sales;


import com.pojo.sales.SalesOrderDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 销售订单细节映射器
 *
 * @author admin
 * @date 2023/06/20
 */
public interface SalesOrderDetailMapper {
    /**
     * 添加销售订单
     *
     * @return int
     */
    //添加销售订单明细表
    @Insert("INSERT INTO sales_order_detail VALUES" +
            " (default," +
            "#{salesOrderNo}," +
            "#{salesOrderId}," +
            "#{productId}," +
            "#{productName}," +
            "#{productQuantity}," +
            "#{productPrice}," +
            "#{totalPrice}," +
            "#{salesDate}," +
            "#{sizeId}," +
            "#{state})")
    int addSalesOrder(SalesOrderDetail salesOrderDetail);

    /**
     * 查询价格
     *
     * @param productId 产品标识
     * @param sizeId    尺寸标识
     * @return {@link Double}
     *///根据产品id和型号id查询价格
    @Select("select price from product_size_specification_price_rel where product_id = #{param1} and size_id = #{param2};")
    Double queryPrice(Integer productId, Integer sizeId);

    /**
     * 查询销售订单明细
     *
     * @param salesOrderId 销售订单id
     * @return {@link List}<{@link SalesOrderDetail}>
     *///根据salesOrderId查询销售订单明细表
    List<SalesOrderDetail> QuerySalesOrderDetail(Long salesOrderId);

    @Update("update sales_order_detail set state =#{stateId} where sales_order_id = #{salesOrderId}")
    int updateStatesById(@Param("stateId") Long stateId, @Param("salesOrderId") Long salesOrderId);
}
